﻿using System;
using System.Diagnostics;
using Terraria.GameContent.UI.Elements;
using Terraria.Localization;
using Terraria.UI;

namespace Terraria.ModLoader.UI
{
	// Token: 0x02000282 RID: 642
	internal class UIErrorMessage : UIState
	{
		// Token: 0x06001A34 RID: 6708 RVA: 0x0042831C File Offset: 0x0042651C
		public override void OnInitialize()
		{
			this.area = new UIElement();
			this.area.Width.Set(0f, 0.8f);
			this.area.Top.Set(200f, 0f);
			this.area.Height.Set(-210f, 1f);
			this.area.HAlign = 0.5f;
			this.message.Width.Set(0f, 1f);
			this.message.Height.Set(-110f, 1f);
			this.message.HAlign = 0.5f;
			this.area.Append(this.message);
			UITextPanel<string> uitextPanel = new UITextPanel<string>(Language.GetTextValue("tModLoader.Continue"), 0.7f, true);
			uitextPanel.Width.Set(-10f, 0.5f);
			uitextPanel.Height.Set(50f, 0f);
			uitextPanel.Top.Set(-108f, 1f);
			uitextPanel.OnMouseOver += UICommon.FadedMouseOver;
			uitextPanel.OnMouseOut += UICommon.FadedMouseOut;
			uitextPanel.OnClick += this.ContinueClick;
			this.area.Append(uitextPanel);
			UITextPanel<string> uitextPanel2 = new UITextPanel<string>(Language.GetTextValue("tModLoader.OpenLogs"), 0.7f, true);
			uitextPanel2.CopyStyle(uitextPanel);
			uitextPanel2.HAlign = 1f;
			uitextPanel2.OnMouseOver += UICommon.FadedMouseOver;
			uitextPanel2.OnMouseOut += UICommon.FadedMouseOut;
			uitextPanel2.OnClick += this.OpenFile;
			this.area.Append(uitextPanel2);
			this.webHelpButton = new UITextPanel<string>(Language.GetTextValue("tModLoader.OpenWebHelp"), 0.7f, true);
			this.webHelpButton.CopyStyle(uitextPanel2);
			this.webHelpButton.Top.Set(-55f, 1f);
			this.webHelpButton.OnMouseOver += UICommon.FadedMouseOver;
			this.webHelpButton.OnMouseOut += UICommon.FadedMouseOut;
			this.webHelpButton.OnClick += this.VisitRegisterWebpage;
			this.area.Append(this.webHelpButton);
			base.Append(this.area);
		}

		// Token: 0x06001A35 RID: 6709 RVA: 0x00012A32 File Offset: 0x00010C32
		public override void OnActivate()
		{
			Netplay.disconnect = true;
			if (string.IsNullOrEmpty(this.webHelpURL))
			{
				this.area.RemoveChild(this.webHelpButton);
				return;
			}
			this.area.Append(this.webHelpButton);
		}

		// Token: 0x06001A36 RID: 6710 RVA: 0x00012A6A File Offset: 0x00010C6A
		internal void SetMessage(string text)
		{
			this.message.SetText(text);
			this.SetWebHelpURL("");
		}

		// Token: 0x06001A37 RID: 6711 RVA: 0x00012A83 File Offset: 0x00010C83
		internal void SetWebHelpURL(string text)
		{
			this.webHelpURL = text;
		}

		// Token: 0x06001A38 RID: 6712 RVA: 0x00012A8C File Offset: 0x00010C8C
		internal void SetGotoMenu(int gotoMenu)
		{
			this.gotoMenu = gotoMenu;
			this.continueAction = null;
		}

		// Token: 0x06001A39 RID: 6713 RVA: 0x00012A9C File Offset: 0x00010C9C
		internal void OverrideContinueAction(Action action)
		{
			this.continueAction = action;
			this.gotoMenu = 10005;
		}

		// Token: 0x06001A3A RID: 6714 RVA: 0x00012AB0 File Offset: 0x00010CB0
		internal void SetFile(string file)
		{
			this.file = file;
		}

		// Token: 0x06001A3B RID: 6715 RVA: 0x00012AB9 File Offset: 0x00010CB9
		private void ContinueClick(UIMouseEvent evt, UIElement listeningElement)
		{
			Main.PlaySound(10, -1, -1, 1, 1f, 0f);
			Action action = this.continueAction;
			if (action != null)
			{
				action();
			}
			Main.menuMode = this.gotoMenu;
		}

		// Token: 0x06001A3C RID: 6716 RVA: 0x00012AEC File Offset: 0x00010CEC
		private void OpenFile(UIMouseEvent evt, UIElement listeningElement)
		{
			Main.PlaySound(10, -1, -1, 1, 1f, 0f);
			Process.Start(this.file);
		}

		// Token: 0x06001A3D RID: 6717 RVA: 0x00012B0F File Offset: 0x00010D0F
		private void VisitRegisterWebpage(UIMouseEvent evt, UIElement listeningElement)
		{
			Main.PlaySound(10, -1, -1, 1, 1f, 0f);
			Process.Start(this.webHelpURL);
		}

		// Token: 0x04001779 RID: 6009
		private UIMessageBox message = new UIMessageBox("");

		// Token: 0x0400177A RID: 6010
		private UIElement area;

		// Token: 0x0400177B RID: 6011
		private int gotoMenu;

		// Token: 0x0400177C RID: 6012
		private string file;

		// Token: 0x0400177D RID: 6013
		private string webHelpURL;

		// Token: 0x0400177E RID: 6014
		private UITextPanel<string> webHelpButton;

		// Token: 0x0400177F RID: 6015
		private Action continueAction;
	}
}
